package com.renren.commons.exception;


import com.renren.commons.result.ResultInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author zhangzhijian
 * @create 2022-09-16 16:58
 */
@Slf4j
@ControllerAdvice
public class OverAllException {

    @ExceptionHandler
    @ResponseBody
    public ResultInfo catchException(Exception exception){

        String clazzName = exception.getClass().getName();
        // 输出日志
        //log.error("全局异常处理---" + clazzName);
        // 判断是否为自定义的异常
//        if (exception instanceof PinXiXiException){
//            return ResultInfo.error(250, ((PinXiXiException) exception).getMessage());
//        }

        exception.printStackTrace();

        return ResultInfo.fail("其他异常！" + exception.getMessage());
    }
}
